package com.sjc.provider.service.impl;

import com.sjc.provider.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("accountServiceConfirm")
public class AccountServiceConfirm implements IAccountService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Transactional
    @Override
    public void increaseAmount(String acctId, double amount) {
        int value = this.jdbcTemplate.update("update tb_account_one set frozen = frozen - ?,amount = amount + ? where acct_id = ?", amount,amount, acctId);
        if (value != 1) {
            throw new IllegalStateException("ERROR!");
        }

        System.out.printf("confirm increase: acct= %s, amount= %7.2f%n", acctId, amount);
    }
}
